<?php
/*
文件校验更新source\admincp\files.md5 
发布前运行此程序生成 discuzfiles.md5手工放置到
checkfiles('./', '\.php', 0, '\.php|\.xml');
*/
error_reporting(0);
$md5data = array();
checkfiles('../', '', 0);
checkfiles('../about/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../css/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../images/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../include/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../js/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../member/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../pic/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../plus/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../rss/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../sitemap/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../special/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../templets/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../uploads/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../url/', '\.php|\.html|\.htm|\.js', 1);
checkfiles('../wangxiao/', '\.php', 1);
checkfiles('../xiangbei/', '\.php|\.html|\.htm|\.js', 1);


$savedatanew = '';
foreach($md5data as $file => $md5) {
$savedatanew .= $md5.' *'.$file."\r\n";
}
$fp = fopen('files.md5', 'w');fwrite($fp, $savedatanew);fclose($fp);
function checkfiles($currentdir, $ext = '', $sub = 1, $skip = '') {
global $md5data, $savedata;
$currentdir = $currentdir;
$dir = opendir($currentdir);
$exts = '/('.$ext.')$/i';
$skips = explode(',', $skip);
while($entry = readdir($dir)) {
  $file = $currentdir.$entry;
  if($entry != '.' && $entry != '..' && (preg_match($exts, $entry) || $sub && is_dir($file)) && !in_array($entry, $skips)) {
   if($sub && is_dir($file)) {
    checkfiles($file.'/', $ext, $sub, $skip);
   } else {
    $md5data[$file] = md5_file($file);
   }
  }
}
}
echo "提示:默认生成在相对目录内,请手动更新<br><br><br><br><br><br><br><h2 style='text-align: center; margin-top: 20px'>files.md5 生成完毕！</h2></span>";
?>